
//
//  ServiceContentHeadCell.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/10/29.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "ServiceContentHeadCell.h"
#import "HomeModel.h"
#import "ServiceModel.h"
#import "TYAttributedLabel.h"
#define kTitleColor [UIColor colorWithRed:242/255.0 green:156/255.0 blue:56/255.0 alpha:1]
@interface ServiceContentHeadCell()
@property (weak, nonatomic) IBOutlet UILabel *generalizeL;
@property (weak, nonatomic) IBOutlet UIImageView *headImg;
@property (weak, nonatomic) IBOutlet UILabel *resourceL;
@property (weak, nonatomic) IBOutlet UILabel *unitL;
@property (weak, nonatomic) IBOutlet UILabel *evaluateL;
@property (weak, nonatomic) IBOutlet UIImageView *startOneIV;
@property (weak, nonatomic) IBOutlet UIImageView *startTwoIV;
@property (weak, nonatomic) IBOutlet UIImageView *startThreeIV;
@property (weak, nonatomic) IBOutlet UIImageView *startFourIV;
@property (weak, nonatomic) IBOutlet UIImageView *startFiveIV;
@property (weak, nonatomic) IBOutlet UILabel *pointL;
@property (weak, nonatomic) IBOutlet UILabel *commonEvaluateL;
@property(nonatomic,assign) int b;
@property (weak, nonatomic) IBOutlet UIButton *collectService;
@property (weak, nonatomic) IBOutlet UILabel *quantityL;
@property (weak, nonatomic) IBOutlet UILabel *collectionL;
@property(nonatomic,strong) TYAttributedLabel *label;
@end
@implementation ServiceContentHeadCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.headImg.layer.masksToBounds = YES;
    self.headImg.layer.cornerRadius = 58/2;
    self.headImg.layer.borderWidth = 1;
    self.headImg.layer.borderColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1].CGColor;
    self.collectService.layer.masksToBounds = YES;
    self.collectService.layer.cornerRadius = 15;
    self.collectService.imageEdgeInsets = UIEdgeInsetsMake(7, 7, 7, 7);
//    self.label= [[TYAttributedLabel alloc]initWithFrame:CGRectMake(18, 0, kUIScreen.size.width-18*2,self.bounds.size.height)];
//    self.label.backgroundColor = kWhite;
//    self.label.font= [UIFont systemFontOfSize:13];
//    self.label.textColor = kLabel102Color;
//    self.label.characterSpacing = 2;
//    self.label.linesSpacing = 5;
//    [self.contentView addSubview:self.label];
    

}
- (IBAction)collectBtn:(UIButton *)sender {
//    sender.selected = !sender.selected;
    if ([self.delegate respondsToSelector:@selector(serviceContentHeadCell:withCollectBtn:withIndexPath:)]) {
        [self.delegate serviceContentHeadCell:self withCollectBtn:sender withIndexPath:self.indexPath];
    }
}
- (void)setIndexPath:(NSIndexPath *)indexPath
{
    _indexPath = indexPath;
}
- (void)setServiceModel:(ServiceModel *)serviceModel
{
    _serviceModel = serviceModel;
    [self.headImg sd_setImageWithURL:[NSURL URLWithString:serviceModel.logo] placeholderImage:[UIImage imageNamed:@"noDataImg"]];
    NSString *resource = [NSString stringWithFormat:@"主要资源:  %@",serviceModel.resource];
    NSMutableAttributedString *resourceS = [[NSMutableAttributedString alloc] initWithString:resource];
    NSRange range2 = [[resourceS string] rangeOfString:@"主要资源: "];
    [resourceS addAttribute:NSForegroundColorAttributeName value:kOrangeBg range:range2];
//    NSMutableParagraphStyle *paragraphStyleResourceS = [[NSMutableParagraphStyle alloc]init];
//    [paragraphStyleResourceS setLineSpacing:4];
//    [resourceS addAttribute:NSParagraphStyleAttributeName
//                   value:paragraphStyleResourceS
//                   range:NSMakeRange(0, [serviceModel.resource length])];
//    self.generalizeL.attributedText = resourceS;
    self.generalizeL.attributedText = resourceS;
    
    NSString *title =[NSString stringWithFormat:@"服务概述:  %@",serviceModel.content];
    NSMutableAttributedString *titleS = [[NSMutableAttributedString alloc] initWithString:title];
    NSRange range1 = [[titleS string] rangeOfString:@"服务概述:  "];
    [titleS addAttribute:NSForegroundColorAttributeName value:kOrangeBg range:range1];
//    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
//    [paragraphStyle setLineSpacing:4];
//    [titleS addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [serviceModel.content length])];
//    self.resourceL.attributedText = titleS;
    self.resourceL.attributedText = titleS;
    
    if (serviceModel.type == 1) {
        NSString *unit = [NSString stringWithFormat:@"服务提供方: 个人(已认证)"];
        NSMutableAttributedString *unitS = [[NSMutableAttributedString alloc] initWithString:unit];
        NSRange range3 = [[unitS string] rangeOfString:@"服务提供方:  "];
        NSRange range4= [[unitS string] rangeOfString:@"已认证"];
        [unitS addAttribute:NSForegroundColorAttributeName value:kOrangeBg range:range3];
        [unitS addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1] range:range4];
        self.unitL.attributedText = unitS;
    }else{
        NSString *unit = [NSString stringWithFormat:@"服务提供方: 企业(已认证)"];
        NSMutableAttributedString *unitS = [[NSMutableAttributedString alloc] initWithString:unit];
        NSRange range3 = [[unitS string] rangeOfString:@"服务提供方:  "];
        NSRange range4= [[unitS string] rangeOfString:@"已认证"];
        [unitS addAttribute:NSForegroundColorAttributeName value:kOrangeBg range:range3];
        [unitS addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1] range:range4];
        self.unitL.attributedText = unitS;

    }
    XLog(@"serviceModel.collectStatus:%ld",serviceModel.collectStatus);
    if (serviceModel.collectStatus ==1) {
        self.collectService.selected = YES;
    }else {
        self.collectService.selected = NO;
    }
    int a = 0;
    double c = 0;
    self.b = 0;
    //向下
    a = floor(serviceModel.evaluateScope);
    XLog(@"a = %d",a);
    c = serviceModel.evaluateScope-a;
    c=c*10;
    XLog(@"c = %.0f",c);
    if (c == 0) {
        self.b = serviceModel.evaluateScope;
        [self startCount];
    }else if(c>=5){
        //    向上
        self.b = ceil(serviceModel.evaluateScope);
        [self startCount];
    }else {
        self.b= a;
        [self startHalfCount];//半颗星
    }
    self.pointL.text = [NSString stringWithFormat:@"%0.1f分",serviceModel.evaluateScope];
    self.commonEvaluateL.text = [NSString stringWithFormat:@"共%ld人评价",serviceModel.evaluateCount];
    self.quantityL.text = [NSString stringWithFormat:@"咨询量: %ld人",serviceModel.consultationCount];
    self.collectionL.text = [NSString stringWithFormat:@"收藏量: %ld人",serviceModel.collectCount];
}
-(void)startCount
{
    if (self.b== 0) {
        self.startOneIV.image = [UIImage imageNamed:@"icon_07"];
        self.startTwoIV.image = [UIImage imageNamed:@"icon_07"];
        self.startThreeIV.image = [UIImage imageNamed:@"icon_07"];
        self.startFourIV.image = [UIImage imageNamed:@"icon_07"];
        self.startFiveIV.image = [UIImage imageNamed:@"icon_07"];
    }
    if (self.b>=1) {
        self.startOneIV.image = [UIImage imageNamed:@"icon_03"];
        self.startTwoIV.image = [UIImage imageNamed:@"icon_07"];
        self.startThreeIV.image = [UIImage imageNamed:@"icon_07"];
        self.startFourIV.image = [UIImage imageNamed:@"icon_07"];
        self.startFiveIV.image = [UIImage imageNamed:@"icon_07"];
    }
    if (self.b >=2){
        self.startTwoIV.image = [UIImage imageNamed:@"icon_03"];
        self.startThreeIV.image = [UIImage imageNamed:@"icon_03"];
        self.startFourIV.image = [UIImage imageNamed:@"icon_07"];
        self.startFiveIV.image = [UIImage imageNamed:@"icon_07"];
    }
    if (self.b >=3){
        self.startThreeIV.image = [UIImage imageNamed:@"icon_03"];
        self.startFourIV.image = [UIImage imageNamed:@"icon_07"];
        self.startFiveIV.image = [UIImage imageNamed:@"icon_07"];
    }
    if (self.b >=4){
        self.startFourIV.image = [UIImage imageNamed:@"icon_03"];
        self.startFiveIV.image = [UIImage imageNamed:@"icon_07"];
    }
    if(self.b >=5){
        self.startFiveIV.image = [UIImage imageNamed:@"icon_03"];
    }
    
}
-(void)startHalfCount
{
    
    if (self.b==1) {
        self.startOneIV.image = [UIImage imageNamed:@"icon_03"];
        self.startTwoIV.image = [UIImage imageNamed:@"icon_05"];
        self.startThreeIV.image = [UIImage imageNamed:@"icon_07"];
        self.startFourIV.image = [UIImage imageNamed:@"icon_07"];
        self.startFiveIV.image = [UIImage imageNamed:@"icon_07"];
    }
    if (self.b == 2){
        self.startOneIV.image = [UIImage imageNamed:@"icon_03"];
        self.startTwoIV.image = [UIImage imageNamed:@"icon_03"];
        self.startThreeIV.image = [UIImage imageNamed:@"icon_05"];
        self.startFourIV.image = [UIImage imageNamed:@"icon_07"];
        self.startFiveIV.image = [UIImage imageNamed:@"icon_07"];
    }
    if (self.b ==3){
        self.startOneIV.image = [UIImage imageNamed:@"icon_03"];
        self.startTwoIV.image = [UIImage imageNamed:@"icon_03"];
        self.startThreeIV.image = [UIImage imageNamed:@"icon_03"];
        self.startFourIV.image = [UIImage imageNamed:@"icon_05"];
        self.startFiveIV.image = [UIImage imageNamed:@"icon_07"];
    }
    if (self.b ==4){
        self.startOneIV.image = [UIImage imageNamed:@"icon_03"];
        self.startTwoIV.image = [UIImage imageNamed:@"icon_03"];
        self.startThreeIV.image = [UIImage imageNamed:@"icon_03"];
        self.startFourIV.image = [UIImage imageNamed:@"icon_03"];
        self.startFiveIV.image = [UIImage imageNamed:@"icon_05"];
    }
    
}
@end
